# -*- coding: utf-8 -*-
# @Time    : 2021/3/24 9:24
# @Author  : huangwei
# @File    : client.py
# @Software: PyCharm
# coding:utf-8
import time
import requests
import json
import base64


def getByte( path ):
    with open(path, 'rb') as f:
        img_byte = base64.b64encode(f.read())  # 二进制读取后变base64编码
    img_str = str(img_byte, encoding='utf-8')  # 转为str
    return img_str


img_path = 'pic/test.jpg'
img_str = getByte(img_path)

# cols 大于等于3列
cols = ["index", "name", "apartment", "signature"]
# cols = ["apartment", "name", "signature"]

requestsss = {'filepath': img_path, 'image': img_str, 'cols': cols}
req = json.dumps(requestsss, ensure_ascii=False).encode()  # 字典数据结构变json(所有程序语言都认识的字符串)
t1 = time.time()
res = requests.post('http://127.0.0.1:6060/', data=req)

t2 = time.time()
print("time:", t2 - t1)
print(res.json())
